import Vue from 'vue'
import Vuex from 'vuex'

Vue.use(Vuex)

export default new Vuex.Store({
  state: {
    object: [],
    arr:[]
  },
  mutations: {
    edit(state,obj1){
      state.arr=[];
      state.arr.push(obj1);
    },
    add(state, obj) {
      state.object=[];
      state.object.push(obj);
      /* if (state.object.length == 0) {
        state.object.push(obj);
      } else {
        for (var i = 0; i < state.object.length; i++) {
          if (state.object[i].image == obj.image && state.object[i].wine == obj.wine && state.object[i].ml == obj.ml) {
            state.object[i].num++;
            break;
          } else {
            if (i == state.object.length - 1) {
              state.object.push(obj);
              i++;
            }
          }
        }
      } */

      /* state.object.some((item,index) =>{
        if(item.image==obj.image&&item.wine==obj.wine&&item.ml==obj.ml){
          state.object[index].num++;
        }else{
          state.object.push(obj);
        }
      }) */
      //state.object.push(obj);
    }
  },
  actions: {
  },
  modules: {
  }
})
